/* Andreas Baum
 * ServerThread.java
 * Handles the interaction between the server and a client
 * CS 78 - Networks - Programming Assignment 1
 */

package ChatServer;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import java.net.ServerSocket;

public class ListenerThread extends Thread {
	BufferedReader keyboardIn =
		new BufferedReader(
				new InputStreamReader( System.in ) );
	private ServerSocket socket = null;
	private int port;
	// This list contains all valid keywords and
	// their correpsonding emotes:


	public ListenerThread(ServerSocket serverSocket, int serverPort) {
		super("ListenerThread");
		this.socket = serverSocket;
		this.port = serverPort;
		this.start();

//		Create a client instance for the admin:
		new AdminClient(); 
	}

	public void run() {
		while (true) {
			// listen for a new connection:
			try {
				// create a client thread to handle the client:
				new ServerThread(socket.accept());
			} catch (IOException e) {
				System.out.println("Accept failed: " + port);
				System.exit(-1);
			}
		}
	}

	public static void handle(String command) {
		System.out.println(command);
	}
}